package com.suneee.trades.dao.impl;

import java.util.Map;
import org.springframework.stereotype.Repository;
import com.suneee.context.page.Page;
import com.suneee.orm.GenericDao;
import com.suneee.orm.util.WhereClauseBuilder;
import com.suneee.trades.bean.SynLogDTO;
import com.suneee.trades.dao.SynLogDao;
import com.suneee.trades.entity.SynLog;

@Repository("synLogDao")
public class SynLogDaoImpl extends GenericDao<SynLog, Integer> implements SynLogDao{

	@Override
	public Page<Map<String, Object>> synchronizeOrderInfo(SynLogDTO dto) {
		StringBuffer sql = new StringBuffer("select log.create_time as createTime,log.num,s.name as shopName ,log.is_success as isSuccess, log.create_user as createUser,cha.`name` AS channelName  from t_syn_log log LEFT JOIN t_shop s on s.shop_id = log.shop_id LEFT JOIN t_channel cha on cha.channel_code = s.channel_code where ");
		WhereClauseBuilder sbf = new WhereClauseBuilder();
		sbf.equals("log.shop_id", dto.getShopId());
		sbf.equals("log.enterprise_code",dto.getEnterpriseCode());
		sbf.between("log.create_time", dto.getSynStartTime(), dto.getSynEndTime());
		sbf.equals("s.channel_Code", dto.getChannelCode());
		sql.append(sbf.getSql());
		
		sql.append(" GROUP BY log.create_time,log.shop_id");
		
		sql.append(" ORDER BY log.create_time desc ");
		
		return this.queryForList(sql.toString(), dto, sbf.getArgs());
		
	}
}
